jsgadget samples

plotly

基本文法

  • いつでもデータのキャンバスはplot_ly(data = df)ではじまる。
  • x = ~変数 y = ~変数 を引数に指定して、データを割り当てる。
  • type引数でグラフのタイプを指定。bar,scatter
  • 色分けはgroup(離散のみ),color(連続も可)

追加設定

plot_lyオブジェクトに対して、layout関数を足していく。
layout(設定したい項目 = list(項目をリストでわたす))が文法。

  • layout(xaxis = list())
  • layout(legend = list)
  • layout(title = "")
  • layout()

二軸

add_trace()

複数プロット

subplot(p1,p2,nrows = 2)とか。

formattable

formattable(df, list())の形式でリストに列名=関数()でメソッドを渡していく。

  • color_tile(“white”,“orange”)
  • normalize_bar()
  • formatter(“span”, style = x ~ ifelse() )
  • style = style(color = “, font.weight =”")
  • formatter(“span”, x ~ digits(x,2))

ifelseの色分け

style = x ~ style(color = ifelse(x > 0, “green”, “red”),
font.weight = ifelse(abs(x) > 1, “bold”, NA)))

アイコンテキスト

style = x ~ style(color = ifelse(x > 0, “green”, “red”), font.weight = ifelse(abs(x) > 1, “bold”, NA)),      ~ icontext(ifelse(2018 > 2017, “arrow-up”, “arrow-down”), 2018)

style = x ~ icontext(ifelse(x, “ok”, “remove”), ifelse(x, “OK”, “NO”)))

サンプル

id name age grade test1_score test2_score final_score registered
1 Bob 28 C 8.9 9.1 9.00 (rank: 06) Yes
2 Ashley 27 A 9.5 9.1 9.30 (rank: 03) No
3 James 30 A 9.6 9.2 9.40 (rank: 02) Yes
4 David 28 C 8.9 9.1 9.00 (rank: 06) No
5 Jenny 29 B 9.1 8.9 9.00 (rank: 06) Yes
6 Hans 29 B 9.3 8.5 8.90 (rank: 08) Yes
7 Leo 27 B 9.3 9.2 9.25 (rank: 04) Yes
8 John 27 A 9.9 9.3 9.60 (rank: 01) No
9 Emily 31 C 8.5 9.1 8.80 (rank: 09) No
10 Lee 30 C 8.6 8.8 8.70 (rank: 10) No

metricsgraphics

基本シンタックスはmjs_xxx、All plots begin with mjs_plot   mjs_plot(x=,y=) %>%

  • mjs_bar()
  • mjs_line() → mjs_add_line()
  • mjs_histogram(bar_margin=, )
  • mjs_point(color_accessor=, size_accessor=)

プロット以外

  • mjs_labs(x=“Weight of Car”, y=“Miles per Gallon”)
  • mjs_add_marker()
  • mjs_add_baseline()
  • mjs_add_legend(legend=c(“X”, “Y”, “Z”))

グリッド

  • mjs_grid(p1, p2, ncol=2)

dygraphs

time series

Jun Ohashi

2019-06-04